package com.china08.yxyapi.api.manage.tec.teaching.lecture.catalog;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.db.res.YxyResBook;
import com.china08.yxyapi.repository.db.YxyResBookRepository;

@CrossOrigin
@RestController
public class LectureBookDetailController {

    @Autowired
    private YxyResBookRepository yxyResBookRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/lecture/book/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object process(HttpServletRequest request, HttpServletResponse response,
            @PathVariable(value = "id") String id) {
        YxyResBook yxyResBook = yxyResBookRepository.findById(id);
        Assert.notNull(yxyResBook, "书籍不存在");
        RespModel respModels = new RespModel();
        respModels.phaseName = yxyResBook.getPhaseName();
        respModels.subjectName = yxyResBook.getSubjectName();
        respModels.versionName = yxyResBook.getVersionName();
        respModels.semesterName = yxyResBook.getSemersterName();
        respModels.phaseId = yxyResBook.getPhaseId();
        respModels.subjectId = yxyResBook.getSubjectId();
        respModels.bookId = id;
        return respModels;
    }

    protected static class RespModel {

        public String bookId;

        public String phaseName;

        public String subjectName;

        public String versionName;

        public String semesterName;

        public String phaseId;

        public String subjectId;

    }
}
